package br.ufjf.getcomp.buscadorceps;

import android.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ViewFlipper;

public class WSCepActivity extends MapActivity implements View.OnClickListenner, View.OnKeyListenner {

	EditText etCEP;
	TextView tvEstado;
	TextView tvCidade;
	TextView tvBairro;
	TextView tvTipoLograd;
	TextView tvLograd;
	TextView tvComplemento;
	Button btnBuscar;
	CepBean cepBean;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wscep);
        flipper = (ViewFlipper) findViewById(R.id.flipper);
        Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
        Animation out = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
        
        flipper.setInAnimation(in);
        flipper.setInAnimation(out);
        
        etCEP = (EditText) findViewById(R.id.etCEP);
        tvEstado = (TextView) findViewById(R.id.tvEstado);
        tvCidade = (TextView) findViewById(R.id.tvCidade);
        tvBairro = (TextView) findViewById(R.id.tvBairro);
        tvTipoLograd =  (TextView) findViewById(R.id.tvTipoLograd);
        tvLograd = (TextView) findViewById(R.id.tvLograd);
        tvComplemento = (TextView) findViewById(R.id.tvComplemento);
        ImageButton imgBtnPesquisar = (ImageButton) findViewById(R.id.imgBtnPesquisar);
        mapView = (mapView) findVieById(R.id.mapView);
        
        LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.zoom);
        zoomLayout.addView(mapView.getZoomControls(),new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        imgBtnPesquisar.setOnClickListenner(this);
        etCEP.setOnKeyListnner(this);
    }
        
        
    @Override
    protected boolean isRoutedDisplay() {
       return false;
    }
        
    


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        
        SubMenu submenu = menu.addsSubMenu(0,1,2,"Modo de Mapa").setIcon(android.R.drawable.ic_menu_mapmode);
        submenu.add(0,2,1,"Trafego");
        submenu.add(0,3,2,"Satelite");
        return true;
        
    }
    
    @Override
    public boolean onCreateOptionsItemSelected(MenuItem item) {
        
        switch (item.getItemId()) {
		case 2:
			mapView.setTraffic(true);
			mapView.setSatellite(false);			
			break;
		case 3:
			mapView.setTraffic(false);
			mapView.setSatellite(true);			
			break;
        }
       return true; 
    }
    
}
